<!-- 课程组件 -->
<template>
  <div class="course-item">
    <div class="course-img">
      <img :src="`https://file.ituring.com.cn/SmallCover/${coverKey}`" alt="" />
      <span class="course-status">{{ playStatus }}</span>
    </div>
    <p class="course-title">{{ title }}</p>
    <div class="course-info">
      <div class="course-info-left">
        <img
          :src="`https://file.ituring.com.cn/SmallCover/${teacherAvatarImageKey}`"
          alt=""
        />
        <span class="course-teacher">{{ teacherName }}</span>
      </div>
      <div class="course-info-right">
        <span class="course-price" :class="isFree?'free':''">{{ price }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: [
    "id",
    "coverKey",
    "title",
    "teacherAvatarImageKey",
    "teacherName",
    "salePrice",
    "liveShowStatus",
  ],
  computed:{
    // 字符串选择
    price() {
      let num = parseInt(this.salePrice);
      if (num == 0) {
        return "免费";
      } else {
        return num + "元";
      }
    },
    // 字符串颜色
    isFree() {
      let num = parseInt(this.salePrice);
      if (num == 0) {
        return true;
      } 
      else {
        return false;
      }
    },
    // 直播状态
    playStatus(){
      if(this.liveShowStatus == 0){
        return '等待直播';
      }else{
        return '正在直播';
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.course-item {
  width: 180px;
  height: 179.2px;
  padding: 0 15px 15px 0;
  .course-img {
    position: relative;
    img {
      width: 165px;
      height: 104px;
    }
    .course-status {
      position: absolute;
      top: 10px;
      right: 10px;
      background-color: var(--tag-font-orange);
      color: #fff;
      font-size: 12px;
      padding: 2px 4px;
    }
  }
  .course-title {
    color: var(--book-name-font-black);
    font-size: 14px;
    margin-top: 10px;
  }
  .course-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    .course-info-left {
      display: flex;
      align-items: center;
      img {
        width: 18px;
        height: 18px;
        border-radius: 18px;
      }
      .course-teacher {
        color: var(--course-teacher-grey);
        font-size: 14px;
        margin-left: 8px;
      }
    }
    .course-info-right {
      .course-price {
        display: block;
        color: var(--book-name-font-black);
        font-size: 14px;
        line-height: 20px;
        margin: 5px 0 0;
        &.free {
          color: var(--tag-font-orange);
        }
      }
    }
  }
}
</style>